﻿//Author:Michal Sporna
//License: https://operationsneakpeek.codeplex.com/license

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Util.Classes
{
    /// <summary>
    /// Here is the information needed to draw the obstacle
    /// </summary>
    public class ObstacleToDraw
    {
        #region properties
        public string ObstacleID;
        public Vector2 Position;//position within cell
        public int CurrentState;//current state-texture 1 or texture 2?
        //instance of obstacle in state 2
        public string ItemState2;//if this obstacle has 2 states,then this is an ID of the second item/state
        public ObstacleToDraw State2Obstacle;
        public bool HasState2;
        public bool Interactive;
        //interactive tool icon
        public Util.Classes.ObstacleToolIcon ToolIcon;
        //help rectangle used to detect when avatar is near the obstacle (used only in interactive obstacles)
        public Rectangle HelpRectangle;
        //width and height of the obstacle
        public int[] Dimensions;
        public bool DimensionsSet;
        public bool Walkable;
        public Helpers.PublicEnums.ObstacleType Type; //type of the obstacle
        public bool IsWater;
        public string TextureName;

        public bool ObstacleShieldTypeSet;
        public Util.Helpers.PublicEnums.ShieldType Shield;

        #endregion

        #region public fields
        //helpers
        public string PosXString;
        public string PosYString;
        public bool IsSpottedByNPC; //set to true, if NPC spots the obstacle
        public double Time1; //this holds value of game time elapsed, to compare it later and see how much time have passed


        #region TEXTURES
        public Texture2D TextureInstance;
        public bool TextureSet;

        #endregion

        #endregion

        #region methods

        /// <summary>
        /// default constructor
        /// </summary>
        public ObstacleToDraw()
        {
            CurrentState = 0;
            Shield = Helpers.PublicEnums.ShieldType.None;

        }

        /// <summary>
        /// Check if avatar is near the obstacle
        /// (not necessarily touching it)
        /// </summary>
        /// <returns></returns>
        public bool IsAvatarNearTheObstacle()
        {
            //declare
            Rectangle avatarRect;

            try
            {

                if (Cache.Avatar != null)
                {
                    avatarRect= new Rectangle((int)Cache.Avatar.FuturePosition.X, (int)Cache.Avatar.FuturePosition.Y, Cache.Avatar.Width,Cache.Avatar.Height);

                    //see if those 2 rectangles intersect:
                    if (avatarRect.Intersects(this.HelpRectangle))
                    {
                        avatarRect = new Rectangle(0, 0, 0, 0);
                        return true;
                    }
                }

                return false;

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return false;
            }
        }

        #endregion
    }
}
